﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF.BytesIO.Serial.Models
{
    public static partial class ExpandClass
    {
        public static string ToBrushString(this Enum e)
        {
            return "#" + Convert.ToUInt32(e).ToString("X2");
        }

        //
        // 摘要:
        //     获取两个字符串之间的值
        //
        // 参数:
        //   str:
        //     原文
        //
        //   beginStr:
        //     开始字符串
        //
        //   endStr:
        //     结束字符串
        //
        //   isLastIndex:
        //     是否匹配最后索引
        public static string GetBetweenValue(this string str, string beginStr, string endStr, bool isLastIndex = false)
        {
            try
            {
                int num = (isLastIndex ? str.LastIndexOf(beginStr) : str.IndexOf(beginStr));
                if (num < 0)
                {
                    return null;
                }

                int num2 = str.Length;
                if (string.IsNullOrEmpty(endStr) && !(endStr == " ") && !(endStr == Environment.NewLine))
                {
                    switch (endStr)
                    {
                        case "\n":
                        case "\r":
                        case "\r\n":
                            break;
                        default:
                            goto IL_0087;
                    }
                }

                num2 = str.IndexOf(endStr, num + beginStr.Length);
                if (num2 < 0)
                {
                    return null;
                }

                goto IL_0087;
            IL_0087:
                return str.Substring(num + beginStr.Length, num2 - num - beginStr.Length);
            }
            catch
            {
                return null;
            }
        }

    }
}
